package com.xuyang.server;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.codehaus.jackson.map.ObjectMapper;

import com.xuyang.utils.MySqlHelper;
import com.xy.bean.BorrowBook;

/**
 * Servlet implementation class SelectBorrowHistory
 */
//flag 1 当前借阅 2历史借阅
public class SelectBorrowHistory extends HttpServlet {
	private static final long serialVersionUID = 1L;
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Content-Type", "charset=utf-8");
		int flag=Integer.valueOf(request.getParameter("flag"));
		String uname=request.getParameter("uname");
		ArrayList<BorrowBook> list=null;
		//如果是查看当前借阅或历史借阅的就返回数据
		if(flag==1||flag==2){
			list=MySqlHelper.getInstance().selectBorrow(flag, uname);
			ObjectMapper mapper=new ObjectMapper();
			String str=mapper.writeValueAsString(list);
			response.getWriter().write(str);
		}
	}
}
